package gases.as3.librarys.compnents.skin
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.Dictionary;
	
	import gases.as3.librarys.compnents.skin.data.BaseSkin;
	import gases.as3.librarys.core.Interface.IDispose;
	
	/**
	 * 皮肤样式管理器 
	 * @author guwanyuan
	 * 
	 */	
	public class SkinStylesMangaer extends EventDispatcher implements IDispose
	{
		private static var _instance:SkinStylesMangaer;
		
		
		public static function get instance():SkinStylesMangaer
		{
			if(!_instance)
			{
				_instance = new SkinStylesMangaer();
			}
			return _instance;
		}
		
		public function SkinStylesMangaer()
		{
			init();
		}
		
		private function init():void
		{
			_skinDataDict = new Dictionary();
		}
		
		/**
		 * 获取皮肤 
		 * @param skinName
		 * @return 
		 * 
		 */		
		public function getSkinData(skinName:String):BaseSkin
		{
			var skin:BaseSkin = _skinDataDict[skinName] as BaseSkin;
			if(!skin)
			{
				throw new Error("此皮肤不存在");
			}
			return skin;
		}
		
		/**
		 * 增加皮肤 
		 * @param skin
		 * 
		 */		
		public function addSkinData(skin:BaseSkin):void
		{
			_skinDataDict[skin.skinname] = skin;
		}
		
		public function dispose():void
		{
			for each(var skin:BaseSkin in _skinDataDict)
			{
				skin.dispose();
			}
			_skinDataDict = null;
		}
		
		private var _skinDataDict:Dictionary;
	}
}




